<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/contract.class.php");
	
	$contract = new Contract(); 
	$cont_code	= $_GET['cont_code'];
	
	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
	
	$data = $contract->getContractData($cont_code);
	
	$company = $contract->companyList();
	$employed = $contract->employedList();
	$eps = $contract->epsList();
	$arp = $contract->arpList();
	$afp = $contract->afpList();
	$asesor = $contract->asesorList();
	$parafiscal = $contract->parafiscalList();
	
	if(isset($_POST['edit']) && $_POST['edit'] == 1){
		$new_data->cont_code			= $_POST['cont_code'];
		$new_data->cont_type 	= trim(mysql_real_escape_string($_POST['cont_type']));
		$new_data->cont_value 		= trim(mysql_real_escape_string($_POST['cont_value']));
		$new_data->cont_sal_periodo    	= trim(mysql_real_escape_string($_POST['cont_sal_periodo']));
		$new_data->cont_sal_value 	= trim(mysql_real_escape_string($_POST['cont_sal_value']));
		$new_data->cont_cargo 	= trim(mysql_real_escape_string($_POST['cont_cargo']));
		$new_data->cont_day_in 	=  cambiarFormatoFecha($_POST['cont_day_in'],2);
		$new_data->cont_day_out 	=  cambiarFormatoFecha($_POST['cont_day_out'],2);
		if (($_POST['cont_funeral']) == ''){
		$new_data->cont_funeral = 0;
		}
		else {
		$new_data->cont_funeral = trim(mysql_real_escape_string($_POST['cont_funeral']));
		}
		if (($_POST['cont_admin']) == ''){
		$new_data->cont_admin = 0;
		}
		else {
		$new_data->cont_admin = trim(mysql_real_escape_string($_POST['cont_admin']));
		}
		if (($_POST['cont_aporte_mutual']) == ''){
		$new_data->cont_aporte_mutual = 0;
		}
		else {
		$new_data->cont_aporte_mutual = trim(mysql_real_escape_string($_POST['cont_aporte_mutual']));
		}
		$new_data->eps_code = trim(mysql_real_escape_string($_POST['eps_code']));
		$new_data->arp_code = trim(mysql_real_escape_string($_POST['arp_code']));
		$new_data->afp_code = trim(mysql_real_escape_string($_POST['afp_code']));
		
		$new_data->cont_name_poliza = trim(mysql_real_escape_string($_POST['cont_name_poliza']));
		if (($_POST['cont_value_poliza']) == ''){
		$new_data->cont_value_poliza = 0;
		}
		else {
		$new_data->cont_value_poliza = trim(mysql_real_escape_string($_POST['cont_value_poliza']));
		}
		$new_data->cont_name_seguro_vida = trim(mysql_real_escape_string($_POST['cont_name_seguro_vida']));
		if (($_POST['cont_value_seguro_vida']) == ''){
		$new_data->cont_value_seguro_vida = 0;
		}
		else {
		$new_data->cont_value_seguro_vida = trim(mysql_real_escape_string($_POST['cont_value_seguro_vida']));
		}
		if (($_POST['cont_value_otros']) == ''){
		$new_data->cont_value_otros = 0;
		}
		else {
		$new_data->cont_value_otros = trim(mysql_real_escape_string($_POST['cont_value_otros']));
		}
		$new_data->cont_name_otros = trim(mysql_real_escape_string($_POST['cont_name_otros']));
		$new_data->ase_code = trim(mysql_real_escape_string($_POST['ase_code']));
		$new_data->para_code = trim(mysql_real_escape_string($_POST['para_code']));
		$new_data->cont_description = trim(mysql_real_escape_string($_POST['cont_description']));
		
		if ( $contract->updateContract($new_data) ){
			$_SESSION["msg_cool"] .= 'El contrato fue actualizado..<br />';
			echo "<script> window.location.href='listContract.php?show_msg=3'</script>";
			
		}
		else{
			$msg_error = true;
			$_SESSION["msg_cool"] .= 'No se pudo actualizar el contrato...<br />';
			echo "<script> window.location.href='listContract.php?show_msg=1'</script>";	
		}		
	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;
?>